package com.cmc.cloud.cmclink.doc.rpcservice.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.cmc.cloud.cmclink.doc.api.document.rep.EqmFreeTimeRespDto;
import com.cmc.cloud.cmclink.doc.rpcservice.MktService;
import com.cmc.cloud.cmclink.mkt.dto.sc.FreeTimeReqVo;
import com.cmc.cloud.cmclink.mkt.dto.sc.FreeTimeRespVo;
import com.cmc.cloud.cmclink.mkt.rpcapi.AgmtRpcApi;
import com.cmes.framework.common.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: 调用营销接口
 * @Author: lzp
 * @Date: 2025/10/30 15:55
 */
@Service
@Slf4j
public class MktServiceImpl implements MktService {

    @Resource
    private AgmtRpcApi agmtRpcApi;

    @Override
    public List<EqmFreeTimeRespDto> queryFreeTime(List<FreeTimeReqVo> freeTimeRegvos) {
        List<EqmFreeTimeRespDto> eqmFreeTimeRespDtos = new ArrayList<>(32);
        try {
            CommonResult<List<FreeTimeRespVo>> commonResult = agmtRpcApi.queryFreeTimes(freeTimeRegvos);
            List<FreeTimeRespVo> freeTimeRateUnitRespVos = commonResult.getCheckedData();
            eqmFreeTimeRespDtos = BeanUtil.copyToList(freeTimeRateUnitRespVos, EqmFreeTimeRespDto.class);
        } catch (Exception e) {
            log.error("请求营销超期费率接口入参{}", JSON.toJSONString(freeTimeRegvos));
            return Collections.emptyList();
        }

        return eqmFreeTimeRespDtos;
    }
}
